<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI小学题库生成器</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <style>
        :root {
            --primary: #4361ee;
            --secondary: #3a0ca3;
            --accent: #4895ef;
            --light: #f8f9fa;
            --dark: #212529;
            --success: #4cc9f0;
            --warning: #f8961e;
            --danger: #f72585;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            color: var(--dark);
            line-height: 1.6;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }
        
        header {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: white;
            padding: 20px 0;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            position: sticky;
            top: 0;
            z-index: 100;
        }
        
        .header-content {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .logo {
            font-size: 24px;
            font-weight: bold;
            display: flex;
            align-items: center;
        }
        
        .logo-icon {
            margin-right: 10px;
            font-size: 28px;
        }
        
        nav ul {
            display: flex;
            list-style: none;
        }
        
        nav ul li {
            margin-left: 20px;
        }
        
        nav ul li a {
            color: white;
            text-decoration: none;
            font-weight: 500;
            padding: 8px 12px;
            border-radius: 4px;
            transition: all 0.3s ease;
        }
        
        nav ul li a:hover {
            background-color: rgba(255, 255, 255, 0.2);
        }
        
        .main-content {
            padding: 40px 0;
            min-height: calc(100vh - 160px);
        }
        
        .page-title {
            text-align: center;
            margin-bottom: 40px;
            color: var(--dark);
            position: relative;
        }
        
        .page-title h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
        }
        
        .page-title p {
            color: #666;
            font-size: 1.1rem;
        }
        
        .page-title::after {
            content: '';
            display: block;
            width: 80px;
            height: 4px;
            background: var(--accent);
            margin: 15px auto;
            border-radius: 2px;
        }
        
        .card {
            background: white;
            border-radius: 12px;
            box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
            padding: 30px;
            margin-bottom: 30px;
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.12);
        }
        
        .btn {
            display: inline-block;
            padding: 12px 24px;
            background: var(--primary);
            color: white;
            border: none;
            border-radius: 50px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 500;
            text-align: center;
            transition: all 0.3s ease;
            text-decoration: none;
            box-shadow: 0 4px 12px rgba(67, 97, 238, 0.2);
        }
        
        .btn:hover {
            background: var(--secondary);
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(67, 97, 238, 0.3);
        }
        
        .btn-outline {
            background: transparent;
            border: 2px solid var(--primary);
            color: var(--primary);
            box-shadow: none;
        }
        
        .btn-outline:hover {
            background: var(--primary);
            color: white;
        }
        
        .btn-accent {
            background: var(--accent);
            box-shadow: 0 4px 12px rgba(72, 149, 239, 0.2);
        }
        
        .btn-accent:hover {
            background: #3a7bc8;
        }
        
        .btn-large {
            padding: 16px 32px;
            font-size: 18px;
        }
        
        .btn-block {
            display: block;
            width: 100%;
        }
        
        .flex-center {
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        .flex-column {
            flex-direction: column;
        }
        
        .text-center {
            text-align: center;
        }
        
        .mb-20 {
            margin-bottom: 20px;
        }
        
        .mb-30 {
            margin-bottom: 30px;
        }
        
        .mt-30 {
            margin-top: 30px;
        }
        
        .features {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 30px;
            margin-bottom: 40px;
        }
        
        .feature-card {
            background: white;
            border-radius: 12px;
            padding: 30px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
            transition: all 0.3s ease;
            text-align: center;
        }
        
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
        }
        
        .feature-icon {
            font-size: 48px;
            color: var(--primary);
            margin-bottom: 20px;
        }
        
        .feature-title {
            font-size: 20px;
            font-weight: 600;
            margin-bottom: 15px;
            color: var(--dark);
        }
        
        .feature-desc {
            color: #666;
            font-size: 16px;
            line-height: 1.6;
        }
        
        .form-group {
            margin-bottom: 25px;
        }
        
        .form-label {
            display: block;
            margin-bottom: 10px;
            font-weight: 500;
            color: var(--dark);
        }
        
        .form-control {
            width: 100%;
            padding: 14px 18px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s ease;
        }
        
        .form-control:focus {
            border-color: var(--primary);
            outline: none;
            box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
        }
        
        .select-wrapper {
            position: relative;
        }
        
        .select-wrapper::after {
            content: '▼';
            position: absolute;
            top: 50%;
            right: 18px;
            transform: translateY(-50%);
            color: var(--primary);
            pointer-events: none;
            font-size: 12px;
        }
        
        select.form-control {
            appearance: none;
            padding-right: 40px;
        }
        
        .question-list {
            margin-top: 30px;
        }
        
        .question-item {
            background: white;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 3px 15px rgba(0, 0, 0, 0.05);
            border-left: 4px solid var(--accent);
            transition: all 0.3s ease;
        }
        
        .question-item:hover {
            transform: translateX(5px);
        }
        
        .question-text {
            font-weight: 500;
            margin-bottom: 12px;
            font-size: 17px;
        }
        
        .answer-text {
            color: var(--success);
            font-weight: 500;
            padding: 10px 15px;
            background-color: rgba(76, 201, 240, 0.1);
            border-radius: 6px;
            display: inline-block;
            margin-top: 8px;
        }
        
        .actions {
            display: flex;
            justify-content: space-between;
            margin-top: 30px;
        }
        
        .save-btn {
            background: var(--success);
            box-shadow: 0 4px 12px rgba(76, 201, 240, 0.2);
        }
        
        .save-btn:hover {
            background: #3ab0d6;
        }
        
        .saved-banks {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
            gap: 25px;
            margin-top: 30px;
        }
        
        .bank-card {
            background: white;
            border-radius: 12px;
            padding: 25px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
            transition: all 0.3s ease;
            border-top: 4px solid var(--primary);
        }
        
        .bank-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
        }
        
        .bank-title {
            font-size: 18px;
            font-weight: 600;
            margin-bottom: 12px;
            color: var(--dark);
        }
        
        .bank-meta {
            display: flex;
            justify-content: space-between;
            color: #666;
            font-size: 14px;
            margin-bottom: 18px;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
        }
        
        .bank-actions {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }
        
        .bank-actions .btn {
            padding: 8px 16px;
            font-size: 14px;
        }
        
        .loading {
            display: none;
            text-align: center;
            padding: 40px;
        }
        
        .spinner {
            width: 50px;
            height: 50px;
            border: 5px solid rgba(67, 97, 238, 0.1);
            border-top-color: var(--primary);
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin: 0 auto 25px;
        }
        
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
        
        .progress-text {
            color: var(--primary);
            font-weight: 500;
            margin-top: 15px;
        }
        
        footer {
            background: var(--dark);
            color: white;
            padding: 30px 0;
            text-align: center;
        }
        
        .footer-content {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .footer-links {
            display: flex;
            list-style: none;
        }
        
        .footer-links li {
            margin-left: 20px;
        }
        
        .footer-links a {
            color: white;
            text-decoration: none;
            transition: color 0.3s ease;
        }
        
        .footer-links a:hover {
            color: var(--accent);
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .header-content {
                flex-direction: column;
            }
            
            nav ul {
                margin-top: 20px;
            }
            
            nav ul li {
                margin: 0 10px;
            }
            
            .features {
                grid-template-columns: 1fr;
            }
            
            .saved-banks {
                grid-template-columns: 1fr;
            }
            
            .footer-content {
                flex-direction: column;
            }
            
            .footer-links {
                margin-top: 20px;
                flex-wrap: wrap;
                justify-content: center;
            }
            
            .footer-links li {
                margin: 5px 10px;
            }
        }
        
        /* 动画效果 */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .fade-in {
            animation: fadeIn 0.6s ease forwards;
        }
        
        .delay-1 { animation-delay: 0.2s; }
        .delay-2 { animation-delay: 0.4s; }
        .delay-3 { animation-delay: 0.6s; }
        
        /* 浮动动画 */
        @keyframes float {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-10px); }
        }
        
        .floating {
            animation: float 3s ease-in-out infinite;
        }
    </style>
</head>
<body>
    <header>
        <div class="container header-content">
            <div class="logo">
                <span class="logo-icon">📚</span>
                <span>AI小学题库生成器</span>
            </div>
            <nav>
                <ul>
                    <li><a href="#" id="nav-home">首页</a></li>
                    <li><a href="#" id="nav-generate">生成题库</a></li>
                    <li><a href="#" id="nav-my-banks">我的题库</a></li>
                </ul>
            </nav>
        </div>
    </header>

    <div class="main-content">
        <div class="container">
            <!-- 首页 -->
            <div id="home-page">
                <div class="page-title">
                    <h1>AI小学题库生成器</h1>
                    <p>智能生成个性化小学练习题，让教学更轻松</p>
                </div>
                
                <div class="card text-center fade-in">
                    <h2 class="mb-20">快速创建适合学生的练习题</h2>
                    <p class="mb-30">选择年级和难度，AI将为您生成20道高质量的练习题及答案</p>
                    <a href="#" class="btn btn-accent btn-large floating" id="start-generate">开始生成题库</a>
                </div>
                
                <div class="features">
                    <div class="feature-card fade-in delay-1">
                        <div class="feature-icon">🧮</div>
                        <h3 class="feature-title">全科目覆盖</h3>
                        <p class="feature-desc">支持数学、语文、英语等小学全科目题库生成，满足不同教学需求</p>
                    </div>
                    <div class="feature-card fade-in delay-2">
                        <div class="feature-icon">📊</div>
                        <h3 class="feature-title">智能难度分级</h3>
                        <p class="feature-desc">根据年级自动调整题目难度，精准匹配学生认知水平</p>
                    </div>
                    <div class="feature-card fade-in delay-3">
                        <div class="feature-icon">💡</div>
                        <h3 class="feature-title">知识点定制</h3>
                        <p class="feature-desc">可指定特定知识点生成题目，针对性强化学习</p>
                    </div>
                </div>
            </div>
            
            <!-- 生成题库页面 -->
            <div id="generate-page" style="display: none;">
                <div class="page-title">
                    <h1>生成新题库</h1>
                    <p>设置参数，创建个性化练习题</p>
                </div>
                
                <div class="card fade-in">
                    <form id="generate-form">
                        <div class="form-group">
                            <label for="grade" class="form-label">年级</label>
                            <div class="select-wrapper">
                                <select id="grade" class="form-control" required>
                                    <option value="">请选择年级</option>
                                    <option value="一年级">一年级</option>
                                    <option value="二年级">二年级</option>
                                    <option value="三年级">三年级</option>
                                    <option value="四年级">四年级</option>
                                    <option value="五年级">五年级</option>
                                    <option value="六年级">六年级</option>
                                </select>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label for="subject" class="form-label">科目</label>
                            <div class="select-wrapper">
                                <select id="subject" class="form-control" required>
                                    <option value="">请选择科目</option>
                                    <option value="数学">数学</option>
                                    <option value="语文">语文</option>
                                    <option value="英语">英语</option>
                                    <option value="科学">科学</option>
                                </select>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label for="difficulty" class="form-label">难度</label>
                            <div class="select-wrapper">
                                <select id="difficulty" class="form-control" required>
                                    <option value="">请选择难度</option>
                                    <option value="基础">基础</option>
                                    <option value="中等">中等</option>
                                    <option value="提高">提高</option>
                                    <option value="竞赛">竞赛</option>
                                </select>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label for="topic" class="form-label">题目主题（可选）</label>
                            <input type="text" id="topic" class="form-control" placeholder="例如：分数运算、古诗词填空、动词时态等">
                        </div>
                        
                        <div class="flex-center mt-30">
                            <button type="submit" class="btn btn-accent btn-large">生成题库</button>
                        </div>
                    </form>
                </div>
                
                <div class="loading" id="loading">
                    <div class="spinner"></div>
                    <p class="progress-text">AI正在努力生成题目，请稍候...</p>
                </div>
                
                <div class="card fade-in" id="result-card" style="display: none;">
                    <h2 class="mb-20">生成的题库</h2>
                    <div class="question-list" id="question-list"></div>
                    
                    <div class="actions">
                        <button class="btn btn-outline" id="regenerate-btn">重新生成</button>
                        <button class="btn save-btn" id="save-bank-btn">保存题库</button>
                    </div>
                </div>
            </div>
            
            <!-- 我的题库页面 -->
            <div id="my-banks-page" style="display: none;">
                <div class="page-title">
                    <h1>我的题库</h1>
                    <p>管理您保存的题库资源</p>
                </div>
                
                <div class="card fade-in">
                    <div class="flex-center flex-column" id="no-banks-message" style="display: none; min-height: 300px;">
                        <div class="text-center">
                            <p class="mb-20" style="font-size: 18px;">您还没有保存任何题库</p>
                            <a href="#" class="btn btn-accent" id="go-generate">去生成题库</a>
                        </div>
                    </div>
                    
                    <div class="saved-banks" id="saved-banks"></div>
                </div>
            </div>
        </div>
    </div>

    <footer>
        <div class="container footer-content">
            <p>© 2025 AI小学题库生成器 | 让教学更智能</p>
            <ul class="footer-links">
                <li><a href="#">关于我们</a></li>
                <li><a href="#">使用帮助</a></li>
                <li><a href="#">隐私政策</a></li>
                <li><a href="#">联系我们</a></li>
            </ul>
        </div>
    </footer>

    <script>
        // 配置 - 在此处填入您的DeepSeek API密钥
        const API_KEY = "sk-c6a7fb0a88f04c45a858716ce9aec15c"; // 替换为您的实际API密钥
        const API_URL = "https://api.deepseek.com/v1/chat/completions";
        
        // 页面导航
        document.getElementById('nav-home').addEventListener('click', function(e) {
            e.preventDefault();
            showPage('home-page');
        });
        
        document.getElementById('nav-generate').addEventListener('click', function(e) {
            e.preventDefault();
            showPage('generate-page');
        });
        
        document.getElementById('nav-my-banks').addEventListener('click', function(e) {
            e.preventDefault();
            showPage('my-banks-page');
            loadSavedBanks();
        });
        
        document.getElementById('start-generate').addEventListener('click', function(e) {
            e.preventDefault();
            showPage('generate-page');
        });
        
        document.getElementById('go-generate').addEventListener('click', function(e) {
            e.preventDefault();
            showPage('generate-page');
        });
        
        function showPage(pageId) {
            document.getElementById('home-page').style.display = 'none';
            document.getElementById('generate-page').style.display = 'none';
            document.getElementById('my-banks-page').style.display = 'none';
            
            document.getElementById(pageId).style.display = 'block';
            window.scrollTo(0, 0);
        }
        
        // 题库生成逻辑
        document.getElementById('generate-form').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const grade = document.getElementById('grade').value;
            const subject = document.getElementById('subject').value;
            const difficulty = document.getElementById('difficulty').value;
            const topic = document.getElementById('topic').value;
            
            if (!grade || !subject || !difficulty) {
                alert('请填写年级、科目和难度');
                return;
            }
            
            // 显示加载状态
            document.getElementById('loading').style.display = 'block';
            document.getElementById('result-card').style.display = 'none';
            
            generateQuestions(grade, subject, difficulty, topic);
        });
        
        document.getElementById('regenerate-btn').addEventListener('click', function() {
            const grade = document.getElementById('grade').value;
            const subject = document.getElementById('subject').value;
            const difficulty = document.getElementById('difficulty').value;
            const topic = document.getElementById('topic').value;
            
            document.getElementById('loading').style.display = 'block';
            document.getElementById('result-card').style.display = 'none';
            
            generateQuestions(grade, subject, difficulty, topic);
        });
        
        async function generateQuestions(grade, subject, difficulty, topic) {
            try {
                const prompt = `你是一位专业的小学${subject}老师，请为${grade}学生生成20道${difficulty}难度的${subject}练习题${
                    topic ? '，主题是关于"' + topic + '"' : ''
                }。要求：
                1. 题目难度要符合${grade}学生水平
                2. 每题单独一行，格式为：题号. 题目内容
                3. 每题后面跟着一行答案，格式为：答案：答案内容
                4. 题目类型多样，覆盖重要知识点
                5. 答案要准确详细`;
                
                const response = await axios.post(API_URL, {
                    model: "deepseek-chat",
                    messages: [
                        {
                            role: "system",
                            content: prompt
                        }
                    ],
                    temperature: 0.7,
                    max_tokens: 2000
                }, {
                    headers: {
                        'Authorization': `Bearer ${API_KEY}`,
                        'Content-Type': 'application/json'
                    }
                });
                
                const content = response.data.choices[0].message.content;
                const questions = parseQuestions(content);
                
                displayQuestions(questions, grade, subject, difficulty, topic);
                
                // 隐藏加载状态，显示结果
                document.getElementById('loading').style.display = 'none';
                document.getElementById('result-card').style.display = 'block';
                
            } catch (error) {
                console.error('生成题目失败:', error);
                document.getElementById('loading').style.display = 'none';
                alert('生成题目失败，请检查API密钥或稍后重试');
            }
        }
        
        function parseQuestions(content) {
            const lines = content.split('\n').filter(line => line.trim() !== '');
            const questions = [];
            let currentQuestion = null;
            
            for (const line of lines) {
                if (line.match(/^\d+\.\s/)) {
                    // 这是题目行
                    if (currentQuestion) {
                        questions.push(currentQuestion);
                    }
                    currentQuestion = {
                        question: line.replace(/^\d+\.\s/, ''),
                        answer: ''
                    };
                } else if (line.startsWith('答案：') && currentQuestion) {
                    // 这是答案行
                    currentQuestion.answer = line.replace('答案：', '').trim();
                } else if (currentQuestion) {
                    // 可能是答案的延续
                    currentQuestion.answer += '\n' + line.trim();
                }
            }
            
            if (currentQuestion) {
                questions.push(currentQuestion);
            }
            
            return questions.slice(0, 20); // 确保只返回20题
        }
        
        function displayQuestions(questions, grade, subject, difficulty, topic) {
            const questionList = document.getElementById('question-list');
            questionList.innerHTML = '';
            
            questions.forEach((q, index) => {
                const questionItem = document.createElement('div');
                questionItem.className = 'question-item fade-in';
                questionItem.style.animationDelay = `${index * 0.05}s`;
                questionItem.innerHTML = `
                    <div class="question-text">${index + 1}. ${q.question}</div>
                    <div class="answer-text">答案：${q.answer}</div>
                `;
                questionList.appendChild(questionItem);
            });
            
            // 保存生成参数到按钮数据属性
            const saveBtn = document.getElementById('save-bank-btn');
            saveBtn.dataset.grade = grade;
            saveBtn.dataset.subject = subject;
            saveBtn.dataset.difficulty = difficulty;
            saveBtn.dataset.topic = topic || '';
        }
        
        // 保存题库
        document.getElementById('save-bank-btn').addEventListener('click', function() {
            const grade = this.dataset.grade;
            const subject = this.dataset.subject;
            const difficulty = this.dataset.difficulty;
            const topic = this.dataset.topic;
            
            const questions = [];
            const questionElements = document.querySelectorAll('.question-item');
            
            questionElements.forEach((el, index) => {
                const questionText = el.querySelector('.question-text').textContent.replace(`${index + 1}. `, '');
                const answerText = el.querySelector('.answer-text').textContent.replace('答案：', '').trim();
                
                questions.push({
                    question: questionText,
                    answer: answerText
                });
            });
            
            const bank = {
                id: Date.now(),
                title: `${grade}${subject}${difficulty}题库${topic ? ' - ' + topic : ''}`,
                grade,
                subject,
                difficulty,
                topic,
                questions,
                date: new Date().toLocaleDateString('zh-CN', {
                    year: 'numeric',
                    month: '2-digit',
                    day: '2-digit'
                })
            };
            
            saveBank(bank);
            alert('题库保存成功！');
            loadSavedBanks();
            showPage('my-banks-page');
        });
        
        function saveBank(bank) {
            let banks = JSON.parse(localStorage.getItem('questionBanks')) || [];
            banks.unshift(bank); // 新题库添加到前面
            localStorage.setItem('questionBanks', JSON.stringify(banks));
        }
        
        // 加载保存的题库
        function loadSavedBanks() {
            const banks = JSON.parse(localStorage.getItem('questionBanks')) || [];
            const savedBanksContainer = document.getElementById('saved-banks');
            const noBanksMessage = document.getElementById('no-banks-message');
            
            savedBanksContainer.innerHTML = '';
            
            if (banks.length === 0) {
                noBanksMessage.style.display = 'flex';
                return;
            }
            
            noBanksMessage.style.display = 'none';
            
            banks.forEach((bank, index) => {
                const bankCard = document.createElement('div');
                bankCard.className = 'bank-card fade-in';
                bankCard.style.animationDelay = `${index * 0.1}s`;
                bankCard.innerHTML = `
                    <h3 class="bank-title">${bank.title}</h3>
                    <div class="bank-meta">
                        <span>${bank.grade} · ${bank.subject}</span>
                        <span>${bank.date}</span>
                    </div>
                    <div class="bank-actions">
                        <button class="btn btn-outline view-bank-btn" data-id="${bank.id}">查看</button>
                        <button class="btn btn-outline delete-bank-btn" data-id="${bank.id}">删除</button>
                    </div>
                `;
                savedBanksContainer.appendChild(bankCard);
            });
            
            // 添加查看和删除按钮的事件监听
            document.querySelectorAll('.view-bank-btn').forEach(btn => {
                btn.addEventListener('click', function() {
                    const bankId = parseInt(this.getAttribute('data-id'));
                    viewBank(bankId);
                });
            });
            
            document.querySelectorAll('.delete-bank-btn').forEach(btn => {
                btn.addEventListener('click', function() {
                    const bankId = parseInt(this.getAttribute('data-id'));
                    if (confirm('确定要删除这个题库吗？此操作不可撤销。')) {
                        deleteBank(bankId);
                    }
                });
            });
        }
        
        function viewBank(bankId) {
            const banks = JSON.parse(localStorage.getItem('questionBanks')) || [];
            const bank = banks.find(b => b.id === bankId);
            
            if (!bank) return;
            
            // 显示问题和答案
            displayQuestions(bank.questions, bank.grade, bank.subject, bank.difficulty, bank.topic);
            document.getElementById('result-card').style.display = 'block';
            
            // 设置表单值
            document.getElementById('grade').value = bank.grade;
            document.getElementById('subject').value = bank.subject;
            document.getElementById('difficulty').value = bank.difficulty;
            document.getElementById('topic').value = bank.topic || '';
            
            // 切换到生成页面
            showPage('generate-page');
            window.scrollTo(0, document.getElementById('result-card').offsetTop);
        }
        
        function deleteBank(bankId) {
            let banks = JSON.parse(localStorage.getItem('questionBanks')) || [];
            banks = banks.filter(b => b.id !== bankId);
            localStorage.setItem('questionBanks', JSON.stringify(banks));
            loadSavedBanks();
        }
        
        // 初始化显示首页
        showPage('home-page');
    </script>
</body>
</html>